//
//  HGGoodsOderCell.m
//  RedWinMall
//
//  Created by HeDianZhao on 2018/8/6.
//  Copyright © 2018年 HeDianZhao. All rights reserved.
//

#import "HGGoodsOderCell.h"
#import "HGGoodsModel.h"

@interface HGGoodsOderCell ()

@property (strong, nonatomic)UIImageView *goodsimage;

@property (strong, nonatomic)UILabel *goodsNameLabel;

@property (strong, nonatomic)UILabel *goodsMoenyLabel;

@property (strong, nonatomic)UILabel *goodsTypeLabel;

@property (strong, nonatomic)UILabel *goodsCountLabel;

@property (strong, nonatomic)UILabel *infoLabel;

@end

@implementation HGGoodsOderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
    }
    return self;
}

- (void)setModel:(HGGoodsModel *)model {
    _model = model;
    [_goodsimage sd_setImageWithURL:kPhotoURL(model.faceImg) placeholderImage:[UIImage imageNamed:@""] options:(SDWebImageProgressiveDownload)];
    _goodsNameLabel.text = [NSString stringWithFormat:@"%@\n6支/箱",model.productName];
    [Utility fuwenbenLabel:_goodsNameLabel fontNumber:[UIFont systemFontOfSize:14] andRange:NSMakeRange(_goodsNameLabel.text.length - 4, 4) andColor:kColorDefult];
    _goodsMoenyLabel.text = model.rmbPrice;
    _goodsCountLabel.text = [NSString stringWithFormat:@"x%ld",model.num];
    
    _infoLabel.text = [NSString stringWithFormat:@"共%ld件 合计%@(含运费￥0.00)",model.num,model.payAmountRmb];
    
    [Utility fuwenbenLabel:_infoLabel fontNumber:[UIFont systemFontOfSize:17] andRange:NSMakeRange(_goodsCountLabel.text.length + 4, model.rmbPrice.length) andColor:kColorText];
    
    if (model.sendState == 1 && model.state == 2) {
        _goodsTypeLabel.text = @"等待卖家发货";
    } else if (model.sendState == 2 && model.state == 2) {
        _goodsTypeLabel.text = @"卖家已发货";
    } else {
        _goodsTypeLabel.text = model.stateText;
    }
}

- (void)setType:(NSInteger)type {
    _infoLabel.hidden = YES;
}

- (void)initSubViews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGFloat margin = 14;
    
    _goodsimage = [[UIImageView alloc] init];
    _goodsimage.backgroundColor = kColorBackground;
    _goodsimage.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:_goodsimage];
    
    [_goodsimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(margin);
        make.left.offset(margin);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    
    _goodsNameLabel = [[UILabel alloc] init];
    _goodsNameLabel.font = [UIFont systemFontOfSize:14];
    _goodsNameLabel.textColor = kColorDefult;
    _goodsNameLabel.numberOfLines = 2;
    _goodsNameLabel.text = @"拉菲庄园至尊红酒\n6支/箱";
    [self.contentView addSubview:_goodsNameLabel];
    
    [_goodsNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsimage.mas_right).offset(margin);
        make.top.equalTo(self.goodsimage).offset(5);
    }];
    
    _goodsMoenyLabel = [[UILabel alloc] init];
    _goodsMoenyLabel.font = [UIFont systemFontOfSize:12];
    _goodsMoenyLabel.text = @"￥6888.00";
    _goodsMoenyLabel.textColor = kColorMainTheme;
    [self.contentView addSubview:_goodsMoenyLabel];
    
    [_goodsMoenyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsNameLabel);
        make.top.equalTo(_goodsNameLabel.mas_bottom).offset(margin/2);
    }];
    
    
    _goodsTypeLabel = [[UILabel alloc] init];
    _goodsTypeLabel.font = [UIFont systemFontOfSize:12];
    _goodsTypeLabel.text = @"等待卖家付款";
    _goodsTypeLabel.textColor = kColorMainTheme;
    [self.contentView addSubview:_goodsTypeLabel];
    
    [_goodsTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_goodsNameLabel);
        make.right.offset(-margin);
    }];
    
    _goodsCountLabel = [[UILabel alloc] init];
    _goodsCountLabel.font = [UIFont systemFontOfSize:12];
    _goodsCountLabel.text = @"x1";
    _goodsCountLabel.textColor = kColorText;
    [self.contentView addSubview:_goodsCountLabel];
    
    [_goodsCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_goodsMoenyLabel);
        make.right.equalTo(_goodsTypeLabel);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = kColorBackground;
    [self.contentView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(-margin);
        make.top.equalTo(_goodsCountLabel.mas_bottom).offset(margin);
        make.right.equalTo(self.contentView);
        make.height.offset(1);
    }];
    
    _infoLabel = [[UILabel alloc] init];
    _infoLabel.font = [UIFont systemFontOfSize:12];
    _infoLabel.text = @"---------";
    _infoLabel.textColor = kColorText;
    [self.contentView addSubview:_infoLabel];
    
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView.mas_bottom).offset(margin);
        make.right.offset(-margin);
    }];
    
}

@end

@implementation HGPaymentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
    }
    return self;
}


- (void)initSubViews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIButton *fkButton = [[UIButton alloc] init];
    fkButton.tag = 1000;
    [fkButton setTitle:@"付款" forState:(UIControlStateNormal)];
    fkButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [fkButton setTitleColor:kColorMainTheme forState:(UIControlStateNormal)];
    fkButton.layer.cornerRadius = 3.5;
    fkButton.layer.borderWidth = 1;
    fkButton.layer.borderColor = kColorMainTheme.CGColor;
    [fkButton addTarget:self action:@selector(tap:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:fkButton];
    
    [fkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.offset(-14);
        make.size.mas_equalTo(CGSizeMake(60, 25));
    }];
    
    
    UIButton *qxButton = [[UIButton alloc] init];
    qxButton.tag = 1001;
    qxButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [qxButton setTitle:@"取消订单" forState:(UIControlStateNormal)];
    [qxButton setTitleColor:kColorText forState:(UIControlStateNormal)];
    qxButton.layer.cornerRadius = 3.5;
    qxButton.layer.borderWidth = 1;
    qxButton.layer.borderColor = kColorText.CGColor;
    [qxButton addTarget:self action:@selector(tap:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:qxButton];
    
    [qxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(fkButton);
        make.right.equalTo(fkButton.mas_left).offset(-10);
        make.size.mas_equalTo(CGSizeMake(80, 25));
    }];
}

- (void)tap:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(tapAction:withModel:indexPath:)]) {
        [_delegate tapAction:sender.tag - 1000 withModel:_models.firstObject indexPath:_indexPath];
    }
}

@end


@implementation HGPaymentBeenCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
    }
    return self;
}


- (void)initSubViews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIButton *fkButton = [[UIButton alloc] init];
    fkButton.tag = 1002;
    [fkButton setTitle:@"确认收货" forState:(UIControlStateNormal)];
    fkButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [fkButton setTitleColor:kColorMainTheme forState:(UIControlStateNormal)];
    fkButton.layer.cornerRadius = 3.5;
    fkButton.layer.borderWidth = 1;
    fkButton.layer.borderColor = kColorMainTheme.CGColor;
    [fkButton addTarget:self action:@selector(tap:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:fkButton];
    
    [fkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.offset(-14);
        make.size.mas_equalTo(CGSizeMake(80, 25));
    }];
    
    
    UIButton *qxButton = [[UIButton alloc] init];
    qxButton.tag = 1003;
    qxButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [qxButton setTitle:@"查看物流" forState:(UIControlStateNormal)];
    [qxButton setTitleColor:kColorText forState:(UIControlStateNormal)];
    qxButton.layer.cornerRadius = 3.5;
    qxButton.layer.borderWidth = 1;
    qxButton.layer.borderColor = kColorText.CGColor;
    [qxButton addTarget:self action:@selector(tap:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:qxButton];
    
    [qxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(fkButton);
        make.right.equalTo(fkButton.mas_left).offset(-10);
        make.size.mas_equalTo(CGSizeMake(80, 25));
    }];
}

- (void)tap:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(tapAction:withModel:indexPath:)]) {
        [_delegate tapAction:sender.tag - 1000 withModel:_models.firstObject indexPath:_indexPath];
    }
}

@end


@implementation HGCmpBeenCell {
    UIButton *fkButton;
    UIButton *delButton;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
    }
    return self;
}

- (void)setIsDel:(BOOL)isDel {
    _isDel = isDel;
    if (isDel == YES) {
        fkButton.hidden = YES;
        delButton.hidden = NO;
    } else {
        fkButton.hidden = NO;
        delButton.hidden = YES;
    }
}

- (void)initSubViews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    fkButton = [[UIButton alloc] init];
    fkButton.tag = 1003;
    [fkButton setTitle:@"查看物流" forState:(UIControlStateNormal)];
    fkButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [fkButton setTitleColor:kColorMainTheme forState:(UIControlStateNormal)];
    fkButton.layer.cornerRadius = 3.5;
    fkButton.layer.borderWidth = 1;
    fkButton.layer.borderColor = kColorMainTheme.CGColor;
    [fkButton addTarget:self action:@selector(tap:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:fkButton];
    
    [fkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.offset(-14);
        make.size.mas_equalTo(CGSizeMake(80, 25));
    }];
    
    delButton = [[UIButton alloc] init];
    delButton.hidden = YES;
    delButton.tag = 1004;
    [delButton setTitle:@"删除订单" forState:(UIControlStateNormal)];
    delButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [delButton setTitleColor:kColorMainTheme forState:(UIControlStateNormal)];
    delButton.layer.cornerRadius = 3.5;
    delButton.layer.borderWidth = 1;
    delButton.layer.borderColor = kColorMainTheme.CGColor;
    [delButton addTarget:self action:@selector(tap:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:delButton];
    
    [delButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.offset(-14);
        make.size.mas_equalTo(CGSizeMake(80, 25));
    }];
}

- (void)tap:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(tapAction:withModel:indexPath:)]) {
        [_delegate tapAction:sender.tag - 1000 withModel:_models.firstObject indexPath:_indexPath];
    }
}

@end
